home *** CD-ROM | disk | FTP | other *** search
- /* WARNING: THIS EXAMPLE IS QUICK & DIRTY!!! Its only purpose is to */
- /* demonstrate how certain MB_lib functions are used and how they work. */
- /* While the code is a functional program, no attempt has been made to */
- /* clean up the code or to streamline it, and I've economized a bit on */
- /* error checking since I've made this in a hurry. However, if you're */
- /* able to use MB_lib, odds are that you also know how to write neat code. */
-
- /* Display messages to a certain user */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "mb_lib.h"
-
- long recnr;
- MSGHDR_RECORD hdr;
- MSGTOIDX_RECORD to;
- M_TEXT txt;
-
- void printmsg (MSGHDR_RECORD *); /* Print message on screen */
- int printline (char *); /* Print line to screen */
-
-
- main () {
- if (msg_open ("C:\\MSGBASE")) {
- printf ("Error %d opening message base:\n%s\n", errortype, errorstring);
- exit (1);
- }
- puts ("User name?");
- gets (to);
- printf ("\n\nScanning for unread mail to %s\n", to);
- recnr = msg_firstto (& to);
- while (recnr != -1) {
- msg_read_hdr (recnr, & hdr); /* Ignore errors for the moment */
- printmsg (& hdr); /* Sloppy, but this is just a demo */
- strcpy (to, "* Received *");
- if (msg_lock ("C:\\RA\\SEMAFORE")) {
- puts ("Error locking message base");
- exit (1);
- }
- msg_write_toidx (recnr, & to); /* Mark message as received */
- msg_unlock (); /* Again, ignore errors */
- recnr = msg_nextto (recnr);
- }
- msg_close ();
- puts ("Done.");
- return (0);
- }
-
- void printmsg (MSGHDR_RECORD * hdr) { /* Print a message on screen */
- printf ("By: %s\n", hdr -> who_from);
- printf ("To: %s\n", hdr -> who_to);
- printf ("Re: %s\n", hdr -> subject);
- printf ("Number: %5d Board: %3d\n", hdr -> msgnum, hdr -> board);
- puts ("===================================================");
- txt = msg_read_text (hdr);
- if (txt == NULL) {
- printf ("MB_lib error %d: %s\n", errortype, errorstring);
- exit (1);
- }
- txt_dump (txt, printline, 70, NOKLUDGES); /* Print margin 70, no kludges */
- }
-
-
- int printline (char * line) { /* Print a message line on screen */
- puts (line);
- return (0); /* This always works :-) */
- }
-
-